<template>
  <div class="app-container">
    <el-form :inline="true" :model="SelectCondition" class="demo-form-inline">
      <el-form-item label="讲师姓名">
        <el-input v-model="SelectCondition.name" placeholder="审批人"></el-input>
      </el-form-item>
      <el-form-item label="讲师头衔">
        <el-select v-model="SelectCondition.level" placeholder="讲师头衔">
          <el-option label="高级讲师" value="1"></el-option>
          <el-option label="首席讲师" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="任职时间">
        <div class="block">
          <el-date-picker
            v-model="SelectCondition.begin"
            type="datetime"
            placeholder="开始范围"
            value-format="yyyy-MM-dd HH:mm:ss"
            align="right">
          </el-date-picker>
        </div>
      </el-form-item>
      <el-form-item>
        <div class="block">
          <el-date-picker
            v-model="SelectCondition.end"
            type="datetime"
            placeholder="结束范围"
            value-format="yyyy-MM-dd HH:mm:ss"
            align="right">
          </el-date-picker>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="name"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="career"
        label="资历">
      </el-table-column>
      <el-table-column
        label="头衔">
        <template slot-scope="scope">
          {{scope.row.level===1?"高级讲师":"首席讲师"}}
        </template>
      </el-table-column>
      <el-table-column
        prop="gmtCreate"
        label="添加时间">
      </el-table-column>
      <el-table-column
        prop="intro"
        label="简介">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <router-link :to="'/teacher/teacherEdit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">
              修改
            </el-button>
          </router-link>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete( scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="margin-top: 10px"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="current"
      :page-sizes="[5,10,15]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>

 import { getTeacherList,deleteTeacherById } from '@/api/Teacher';

export default {

  data() {
    return {
      loading:false,
      total:0,
      tableData:[],
      current:1,
      size: 10,
      SelectCondition:{}
    }
  },

  created() {
    this.getTeacherListPlus()
  },

  methods: {
    onSubmit(){
      this.getTeacherListPlus()
      this.SelectCondition = {}
    },
    handleCurrentChange(current){
      this.current = current
      this.getTeacherListPlus()
    },
    handleSizeChange(size){
      this.size = size
      this.getTeacherListPlus()
    },
    handleEdit(){

    },
    handleDelete(row){
      this.$confirm('此操作将永久删除该信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteTeacherById(row.id).then(res=>{
          this.$notify({
            title: '操作成功',
            type: 'success',
            message: res.message
          })
          this.getTeacherListPlus()
        })
      })
    },
    getTeacherListPlus(){
      this.loading = true
      getTeacherList(this.current,this.size,this.SelectCondition).then(res=>{
        this.tableData = res.data.records
        this.total = res.data.total
        this.loading = false
      })
    }
  }

}
</script>

